@model OrchardCore.ContentFields.ViewModels.EditHtmlFieldViewModel
@using Newtonsoft.Json.Linq;
@using OrchardCore.ContentManagement.Metadata.Models
@using OrchardCore.ContentFields.Settings;

@{
    var settings = Model.PartFieldDefinition.GetSettings<HtmlFieldSettings>();
    var trumbowygSettings = Model.PartFieldDefinition.GetSettings<HtmlFieldTrumbowygEditorSettings>();
    var culture = await Orchard.GetContentCultureAsync(Model.Field.ContentItem);
}

<script asp-name="trumbowyg-plugins" depends-on="admin" version="2" at="Foot"></script>
<style asp-name="trumbowyg-plugins" version="2"></style>
@if(trumbowygSettings.InsertMediaWithUrl)
{
<script asp-src="~/OrchardCore.ContentFields/Scripts/trumbowyg.media.url.min.js" debug-src="~/OrchardCore.ContentFields/Scripts/trumbowyg.media.url.js" depends-on="trumbowyg" at="Foot"></script>
}
else
{
<script asp-src="~/OrchardCore.ContentFields/Scripts/trumbowyg.media.tag.min.js" debug-src="~/OrchardCore.ContentFields/Scripts/trumbowyg.media.tag.js" depends-on="trumbowyg" at="Foot"></script>
}

<div class="form-group">
    <label asp-for="Html">@Model.PartFieldDefinition.DisplayName()</label>
    @if (culture.IsRightToLeft())
    {
        <div style="text-align:right">
            <textarea asp-for="Html" class="form-control"></textarea>
        </div>
    }
    else
    {
        <textarea asp-for="Html" class="form-control"></textarea>
    }

    @if (!String.IsNullOrEmpty(settings.Hint))
    {
        <span class="hint">@settings.Hint</span>
    }
</div>

<script at="Foot">
    $(function () {
        $('#@Html.IdFor(m => m.Html)').trumbowyg(@Html.Raw(trumbowygSettings.Options)).on('tbwchange', function () {
            $(document).trigger('contentpreview:render');
        });
    });
    $.trumbowyg.svgPath = '/OrchardCore.Resources/Styles/ui/icons.svg';
</script>
